<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@include file="/WEB-INF/commons/taglibs.jsp"%>
<%@include file="/WEB-INF/commons/common-header.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
	$(function() {
		$("#add").click(function() {
			location.href = "${ctx}/verse/create/";
		});

		$("#del")
				.click(
						function() {
							var items = GrayPlane.select();
							if (items && items.length > 0 && confirm("你确定要删除这些内容吗?")) {
								$('input[name="_method"]').remove();
								$("#myForm")
										.attr("action", "${ctx}/verse/delete/")
										.attr("method", "post")
										.append('<input type="hidden" name="_method" value="DELETE" />')
										.submit();
								//加了这句之后 下面那就不在执行
								return false;
							}
							alert("请先选择要删除的内容");
							return false;
						});
		
		$(".delete").each(function(){
			$this = $(this);
			var id = $this.attr("id");
			$(this).click(function(){
				$.ajax({
					url : "${ctx}/verse/" + id + "/delete/",
					type : "POST",
					data : {"_method":"DELETE"},
					success : function(){
						location.reload();
						parent.frames['left'].location.reload();
					},
					error : function(){
						alert("无法删除该数据！");
					}
				});				
				return false;
			});
		});
	});
</script>
</head>
<body>
	<form id="myForm" action="${ctx }/verse/list/" method="get">
		<ul class="s_bodyR">
			<li class="s_li_head">诗词管理</li>
			<li class="s_brSearch" >
				<span class="s_brsData">数据显示</span>
				<span class="s_brsName">诗歌标题：<input name="params[title]" value="${page.params.title}" type="text" /></span>
				<span class="s_brsButton"><input class="search_submit_btn" type="submit" value="提 交" /></span>
				<p>${message.text }</p></li>
			<li class="s_brTable">
				<table width="100%" border="0" cellspacing="0">
					<tr>
						<th width="5%"><jsp:include page="/WEB-INF/commons/checkall.jsp"></jsp:include>&nbsp;</th>
						<th scope="col">诗词标题</th>
						<th width="8%" scope="col">诗体格律</th>
						<th width="8%" scope="col">作者</th>
						<th width="8%" scope="col">诗词分类</th>
						<th width="8%" scope="col">浏览量</th>
						<th width="6%" scope="col">评分</th>
						<th width="12%" scope="col">创建时间</th>
						<th width="6%" class="s_brtableTD2" scope="col">基本操作</th>
					</tr>
					<c:choose>
						<c:when test="${not empty page.result }">
							<c:forEach items="${page.result }" var="verse">
								<tr>
									<td style="border-left: 0;"><input type="checkbox" name="items" id="checkbox" value="${verse.id}" /></td>
									<td>${verse.title}&nbsp;</td>
									<td>${verse.verseFormat}&nbsp;</td>
									<td>${verse.poet.name}&nbsp;</td>
									<td>${verse.category.name}&nbsp;</td>
									<td>${verse.pageView}&nbsp;</td>
									<td>${verse.rateScore }</td>
									<td class="date">${verse.createTime}&nbsp;</td>
									<td class="s_brtableTD2">		
										<a href="${ctx }/verse/${verse.id}/edit/" class="editor"><span class="s_brtReady">编辑</span></a>&nbsp;
										<a href="#" class="delete" id="${verse.id }">删除</a>&nbsp;
									</td>
								</tr>
							</c:forEach>
						</c:when>
						<c:otherwise>
							<tr>
								<td colspan="7" align="center"><b>暂无内容</b></td>
							</tr>
						</c:otherwise>
					</c:choose>
				</table>
			</li>
			<li class="s_brPage">
				<p class="s_brpLeft">
					<!-- <label><input type="checkbox" />全选</label><button class="s_button">批量有效</button> -->
					<label><a id="add" href="#">新增</a></label>
					<button class="s_button" id="del">批量删除</button>
				</p>
				<p class="s_brpRight">
					<!--page start--><jsp:include page="/WEB-INF/commons/page.jsp" /><!--page end-->
				</p>
			</li>
		</ul>
	</form>
</body>
</html>